/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Actions;

import Randomizer.Randomizer;
import Products.Product;
import com.opensymphony.xwork2.ActionSupport;
import db.DBConnector;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Gabs
 */
public class AddProduct extends ActionSupport {
    
    private Product product;
    private DBConnector db = null;
    private CallableStatement callable = null;
    private String prodtitle,prodsynopsis;
    private int prodid;
    private float prodprice;
    private String prodtype;
   
    
    public AddProduct()
    {}
     
         @Override
        public String execute() throws Exception {
        PreparedStatement pstmt = null;
        Randomizer rand = new Randomizer();
        int productID = rand.GenerateNumber();
    
        db = new DBConnector();
        Connection conn = null;

        try {
            conn = db.getConnection();

          
            
            String createCall = "{call insert_product(?,?,?,?,?,?,?)}";
//---------- calls the insert customer procedure--------------------------------            
            callable = conn.prepareCall(createCall);
            callable.setInt(1, productID);
            callable.setString(2, getProduct().getTitle());
            callable.setString(3, getProduct().getSynopsis());
            callable.setFloat(4, getProduct().getPrice());
            callable.setString(5, getProduct().getISBN());
            callable.setString(6, getProduct().getUPC());
            callable.setString(7, getProduct().getType()); 
            
          
            callable.executeUpdate();
             conn.close();

            return SUCCESS;
        }
        catch (Exception e) {
            Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, e);
            return INPUT;
        }
      }

    /**
     * @return the product
     */
    public Product getProduct() {
        return product;
    }

    /**
     * @param product the product to set
     */
    public void setProduct(Product product) {
        this.product = product;
    }

    /**
     * @return the prodtitle
     */
    public String getProdtitle() {
        return prodtitle;
    }

    /**
     * @param prodtitle the prodtitle to set
     */
    public void setProdtitle(String prodtitle) {
        this.prodtitle = prodtitle;
    }

    /**
     * @return the prodsynopsis
     */
    public String getProdsynopsis() {
        return prodsynopsis;
    }

    /**
     * @param prodsynopsis the prodsynopsis to set
     */
    public void setProdsynopsis(String prodsynopsis) {
        this.prodsynopsis = prodsynopsis;
    }

    /**
     * @return the prodid
     */
    public int getProdid() {
        return prodid;
    }

    /**
     * @param prodid the prodid to set
     */
    public void setProdid(int prodid) {
        this.prodid = prodid;
    }

    /**
     * @return the prodprice
     */
    public float getProdprice() {
        return prodprice;
    }

    /**
     * @param prodprice the prodprice to set
     */
    public void setProdprice(float prodprice) {
        this.prodprice = prodprice;
    }

    /**
     * @return the prodtype
     */
    public String getProdtype() {
        return prodtype;
    }

    /**
     * @param prodtype the prodtype to set
     */
    public void setProdtype(String prodtype) {
        this.prodtype = prodtype;
    }
         
         
  
    
    
    
    
}
